<?php
/**
 * Unfuddle Ticket Model
 * Tickets are represented in the Unfuddle API by the "Ticket" data model. This
 * class contains the properties that make up a "Ticket".
 *
 * @package     Unfuddle
 * @subpackage  Data Models
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @version     $Id: Ticket.php 29 2011-05-09 07:08:53Z luke.visinoni $
 */
class Unfuddle_Model_Ticket extends Unfuddle_Model_Abstract {

    /**
     * Retreive tickets for given project/milestone
     */
    const URI_MILESTONE_TICKETS = '/projects/%d/milestones/%d/tickets';
    const URI_MILESTONE_TICKETS_ACTIVE = '/projects/%d/milestones/%d/tickets_active';
    const URI_MILESTONE_TICKETS_CLOSED = '/projects/%d/milestones/%d/tickets_closed';
    
    /**
     * @var string Model name
     */
    protected $_name = 'ticket';
    
    /**
     * @var array Model fields
     */
    protected $_fields = array(
        'assignee-id' => array('type' => 'integer', 'required' => false, 'read-only' => false),
        'component-id' => array('type' => 'integer', 'required' => false, 'read-only' => false),
        'created-at' => array('type' => 'datetime', 'required' => false, 'read-only' => true),
        'description' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'description-format' => array('type' => 'set', 'required' => false, 'read-only' => true, 'set' => array('markdown', 'textile', 'plain')),
        'description-formatted' => array('type' => 'text', 'required' => false, 'read-only' => true), // only available if formatted=true
        'due-on' => array('type' => 'date', 'required' => false, 'read-only' => false),
        'due-on-formatted' => array('type' => 'text', 'required' => false, 'read-only' => true),
        'field1-value-id' => array('type' => 'integer', 'required' => false, 'read-only' => false),
        'field2-value-id' => array('type' => 'integer', 'required' => false, 'read-only' => false),
        'field3-value-id' => array('type' => 'integer', 'required' => false, 'read-only' => false),
        'hours-estimate-current' => array('type' => 'float', 'required' => false, 'read-only' => false),
        'hours-estimate-initial' => array('type' => 'float', 'required' => false, 'read-only' => false),
        'id' => array('type' => 'integer', 'required' => false, 'read-only' => true),
        'milestone-id' => array('type' => 'integer', 'required' => false, 'read-only' => false),
        'number' => array('type' => 'integer', 'required' => false, 'read-only' => false),
        'priority' => array('type' => 'set', 'required' => true, 'read-only' => false, 'set' => array(1, 2, 3, 4, 5)),
        'project-id' => array('type' => 'integer', 'required' => false, 'read-only' => true),
        'reporter-id' => array('type' => 'integer', 'required' => false, 'read-only' => true),
        'resolution' => array('type' => 'integer', 'required' => false, 'read-only' => false, 'set' => array('fixed', 'works_for_me', 'postponed', 'duplicate', 'will_not_fix', 'invalid')),
        'resolution-description' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'resolution-description-format' => array('type' => 'integer', 'required' => false, 'read-only' => true, 'set' => array('markdown', 'textile', 'plain')),
        'resolution-description-formatted' => array('type' => 'text', 'required' => false, 'read-only' => true), // only available if formatted=true 
        'severity-id' => array('type' => 'integer', 'required' => false, 'read-only' => false),
        'status' => array('type' => 'text', 'required' => false, 'read-only' => false, 'set' => array('new', 'unaccepted', 'reassigned', 'reopened', 'accepted', 'resolved', 'closed')),
        'summary' => array('type' => 'text', 'required' => true, 'read-only' => false),
        'updated-at' => array('type' => 'datetime', 'required' => false, 'read-only' => true),
        'version-id' => array('type' => 'integer', 'required' => false, 'read-only' => false),
        /**
         * The following are not actual ticket attributes, but when creating or updating
         * a ticket, including any of these three attributes instead of the corresponding
         * <fieldN-value-id> attributes will allow you to create a new value for
         * the ticket field if that field is of the "text" disposition.
         */
        'field1-value' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'field2-value' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'field3-value' => array('type' => 'text', 'required' => false, 'read-only' => false),
    );
    
    /**
     * When fetching a ticket or tickets, and you provide comments=true, the
     * return XML will contain a list of comments along with the properties of
     * the ticket. The same goes for attachments. You may also provide these
     * children in an UPDATE call to replace comments 
     */
    protected $_children = array(
        'comments' => array(),
        'attachments' => array(),
    );

}
